package vru;


import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.BulletState;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 *  JUnit test for avoiding bullets.
 *  @author Russell Vea for ICS 314.
 */
public class TwentyTestAvoidance extends RobotTestBed {

  /** The number of kills.*/
  private int misses = 0;
  /** Set to true to print out amount of kills.*/
  private boolean debug = true;
  private int hits = 0;

  /**
   * Specifies that SittingDuck and Destroyer are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() { 
    return "rvu.Lessthan20charsyeah,sample.Corners";
  }

  /*
  public void onRoundStarted(RoundStartedEvent e ) { 
    this.avoidances = 0;
    this.total = 0;
  }*/
  
  /**
   * This test runs for 10 rounds.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }


  /**
   * @param e Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent e) { 
    IBulletSnapshot[] bullets = e.getTurnSnapshot().getBullets();
    for (int i = 0; i < bullets.length; i++) {
      IBulletSnapshot thisBullet = bullets[i];
      //is enemy bullet
      if (thisBullet.getOwnerIndex() == 0) {
        //enemy bullet hit us
        if (thisBullet.getState() == BulletState.HIT_VICTIM) { 
          this.hits++;
        } 
        //the bullet missed
        else if (thisBullet.getState() == BulletState.HIT_WALL) {
          this.misses++;
        }
      }
    }
  }

  /**
   * After the battle, check to see that we've visited the corners.
   *
   * @param e Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent e) {
    if (this.debug) { 
      System.out.println("this.hits: " + this.hits + " this.avoidances: " + this.misses);
    }
    assertTrue("Killed oppononent at leasta 70% of the time", this.misses > this.hits);
  }
  
}
